import 'package:flutter/material.dart';
import 'package:stroke_customer/comm/net/HttpUtil.dart';
import 'package:stroke_customer/comm/net/ServiceUri.dart';
import 'package:stroke_customer/comm/net/UrlAdpater.dart';
import 'package:stroke_customer/model/ServerResponse.dart';
import 'package:stroke_customer/model/comm/CommMenu.dart';

class CustomerIndexMenu extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return new _CustomerIndexMenuState();
  }

}

class _CustomerIndexMenuState extends State<CustomerIndexMenu> {


  CommMenu menus;

  @override
  void initState() {
    super.initState();
    menus = initCommMenu();
  }


  CommMenu getMenuData() {
    return initCommMenu();
  }

  CommMenu getMenuDataByNet() {
    CommMenu temp ;
    Future data = HttpUtil.get(ServiceUri.comCustomerMenu);
    data.then((d){
      Map<String, dynamic> jsonMap =d;
      temp =new  CommMenu.fromJson(jsonMap);
    });
    if(temp==null ){
      print("temp is empty");
    }

    return temp;
  }



  CommMenu initCommMenu() {
    List<Data> dataList = new List();
    Data menu1 = new Data(
        1,
        "",
        "",
        "卒中地图",
        "http://image.bladezoff.com/menu/ditu%402x.png",
        "",
        "Y",
        1,
        "",
        "");
    Data menu11 = new Data(
        1,
        "",
        "",
        "在线咨询",
        "http://image.bladezoff.com/menu/zixun1%402x.png",
        "",
        "Y",
        1,
        "",
        "");
    Data menu12 = new Data(
        1,
        "",
        "",
        "卒中科普",
        "http://image.bladezoff.com/menu/yixuekepu%402x.png",
        "",
        "Y",
        1,
        "",
        "");
    Data menu13 = new Data(
        1,
        "",
        "",
        "健康管理",
        "http://image.bladezoff.com/menu/jiankang%402x.png",
        "",
        "Y",
        1,
        "",
        "");
    Data menu14 = new Data(
        1,
        "",
        "",
        "健康商城",
        "http://image.bladezoff.com/menu/shangcheng@2x.png",
        "",
        "Y",
        1,
        "",
        "");

    dataList.add(menu1);
    dataList.add(menu11);
    dataList.add(menu12);
    dataList.add(menu13);
    dataList.add(menu14);


    return new CommMenu(dataList, "0", "Success");
  }

  List<Widget> createMeun() {
    List <Widget> menuWidget = new List();
    for (int i = 0; i < menus.data.length; i++) {
      Image appMenu = new Image(
          image: NetworkImage(menus.data[i].menuUrl),
          width: 49.0,
          height: 49.0,
          fit: BoxFit.cover
      );

      IconButton button = new IconButton(
          icon: appMenu, onPressed: null

      );
      Text appMenuName = new Text(menus.data[i].menuName);

      Column column = new Column(
        children: <Widget>[button, appMenuName],
      );
      menuWidget.add(column);
    }
    return menuWidget;
  }


  @override
  Widget build(BuildContext context) {
    return new Center(
        child: new Row(
          children: createMeun(),
        )
    );

  }

}
